<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="stylesheet" href="/static/pear/component/pear/css/pear.css" />
    <style>
        .hd-form-upload {
            width: 80px;
            height: 80px;
            display: inline-block;
            cursor: pointer;
        }

        .hd-form-upload input {
            display: none;
        }

        .hd-form-upload span {
            width: 80px;
            height: 80px;
            line-height: 80px;
            text-align: center;
            float: left;
            overflow: hidden;
            background-color: #ddd;
        }

        .hd-form-upload span img {
            width: 100%;
            display: inline;
            vertical-align: middle;
        }

        .hd-form-upload span i {
            width: 80px;
            height: 80px;
            float: left;
            position: relative;
        }

        .hd-form-upload  span i:before {
            content: "";
            border-top: 2px solid #bbb;
            position: absolute;
            top: 39px;
            left: 20px;
            right: 20px;
        }

        .hd-form-upload  span i:after {
            content: "";
            border-right: 2px solid #bbb;
            position: absolute;
            top: 20px;
            left: 39px;
            bottom: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="mainBox  layui-card-body" style="padding: 0 0;">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">快递公司*</label>
                <div class="layui-input-block">
                    <input type="text" name="name" lay-verify="required" placeholder="请输入快递公司名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">logo*</label>
                <div class="layui-input-block">
                    <label class="hd-form-upload" id="image">
                        <span id="thumb-img-thumb">
                            <i></i>
                        </span>
                    </label>
                    <input type="hidden" id="img_thumb" name="logo" value=""/>
                </div>
            </div>
            <div class="layui-input-block">
                <div class="layui-form-mid layui-word-aux">建议宽高208*76</div>
            </div>
        </div>
    </div>


    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-save">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{include file="_Fragment/javascript" /}
<script>
    layui.use(['form', 'jquery', 'upload', 'element', 'croppers'], function() {
        let form = layui.form;
        let upload = layui.upload;
        let croppers = layui.croppers;
        let $ = layui.jquery;

        //创建一个Banner上传组件
        croppers.render({
            elem: '#image'
            //,saveW:750     //保存宽度
            //,saveH:768
            ,mark:2.08/0.76   //选取比例
            ,area:'850px'  //弹窗宽度
            //,url: "https://apilearningsparkminiapp-uat.lorealchina.com/Upload/blob"  //图片上传接口返回和（layui 的upload 模块）返回的JOSN一样
            ,url: "{:url('Pub/blob')}"
            ,done: function(url){ //上传完毕回调
                $("#thumb-img-thumb").html('<img src="'+ url + '" />');
                $("#img_thumb").val(url);
            }
        });


        form.on('submit(user-save)', function(data) {
            let loading = layer.load();
            $.ajax({
                url: '/Express/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    layer.close(loading);
                    if (result.status == 0) {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window
                                .name)); //关闭当前页
                            parent.layui.table.reload("user-table");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>